﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

using VideoPlay.Services;
using VideoPlay.Services.Models;
using VideoPlay.Adapters;

using Funq;

namespace VideoPlay.PhoneClient.ViewModels
{
    public class ContainerLocator : IDisposable
    {
        private bool disposed;

        public Container Container { get; private set; }

        public ContainerLocator()
        {
            this.Container = new Container();
            this.ConfigureContainer();
        }

        public void ConfigureContainer()
        {
            this.Container.Register<IPhoneService>(c => new PhoneService());
            //this.Container.Register<IFavoriteFacade>(c => new FavoriteFacade());
            this.Container.Register<INavigationService>(
                        c => new NavigationService(
                                 ((App)Application.Current).RootFrame));
            this.Container.Register<IndicatorViewModel>(c=>new IndicatorViewModel());
            this.Container.Register<VideoListViewModel>(
                        c => new VideoListViewModel(
                                 c.Resolve<INavigationService>(),
                                 c.Resolve<IPhoneService>(),
                                 c.Resolve<IndicatorViewModel>()));
            this.Container.Register<PlayVideoViewModel>(
                        c => new PlayVideoViewModel(
                                 c.Resolve<INavigationService>(),
                                 c.Resolve<IPhoneService>(),
                                 c.Resolve<IndicatorViewModel>()));
            this.Container.Register<SearchVideoViewModel>(
                        c => new SearchVideoViewModel(
                                 c.Resolve<INavigationService>(),
                                 c.Resolve<IPhoneService>(),
                                 c.Resolve<IndicatorViewModel>()));
            this.Container.Register<VideoShareFBViewModel>(
                        c => new VideoShareFBViewModel(
                                 c.Resolve<INavigationService>(),
                                 c.Resolve<IPhoneService>()));
        }

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (this.disposed)
            {
                return;
            }

            if (disposing)
            {
                this.Container.Dispose();
            }

            this.disposed = true;
        }
    }
}
